//
//  TDUINavigationController.m
//  iosf
//
//  Created by Ye Yuan on 12-3-31.
//  Copyright (c) 2012年 Neusoft Corporation. All rights reserved.
//

#import "TDNavigationController.h"
#import <QuartzCore/QuartzCore.h>

#pragma mark -
#pragma mark Navigator style custom

@implementation UINavigationController(TDCustomStyle)

-(void)setCornerRadius:(CGFloat)cornerRadius
{
    self.view.layer.cornerRadius = cornerRadius;
    self.view.layer.masksToBounds = YES;
}

- (CGFloat)cornerRadius
{
    return self.view.layer.cornerRadius;
}

@end

#pragma mark -
#pragma mark TDNavigationController

@interface TDNavigationController ()

@end

@implementation TDNavigationController
@synthesize pushAnimation=_pushAnimation,popAnimation=_popAnimation;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.pushAnimation=^(UIView *from,UIView *to){
            [UIView transitionWithView:self.view duration:0.3 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
                
            } completion:nil];
        };
        self.popAnimation=^(UIView *baseView){
            [UIView transitionWithView:baseView duration:0.3 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
            
            } completion:nil];
        };
        self.cornerRadius = 0.0f;
    }
    return self;
}

#pragma mark -
#pragma mark Push/Pop View

-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    self.pushAnimation(self.topViewController.view,viewController.view);
    [super pushViewController:viewController animated:NO];
}

-(UIViewController *)popViewControllerAnimated:(BOOL)animated
{
    NSUInteger count = self.viewControllers.count;
    if (count > 1) {
        self.popAnimation(self.view);
        return [super popViewControllerAnimated:NO];
    }
    return nil;
}

-(NSArray *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    NSUInteger count = self.viewControllers.count;
    if (count > 1) {
        self.popAnimation(self.view);
        return [super popToViewController:viewController animated:NO];
    }
    return nil;
}

-(NSArray *)popToRootViewControllerAnimated:(BOOL)animated
{
    NSUInteger count = self.viewControllers.count;
    if (count > 1) {
        self.popAnimation(self.view);
        return [super popToRootViewControllerAnimated:NO];
    }
    return nil;
}

@end
